from django.contrib.auth.models import Permission, ContentType
from rest_framework.viewsets import ModelViewSet
from rest_framework.decorators import action
from rest_framework.response import Response
from meiduo_admin.serializers.permission_serializers import PermissionSerializer, ContentTypeSerializer
from meiduo_admin.utils import MyPagination


class PermissionView(ModelViewSet):
    """ 用户权限表 增删改查 """

    queryset = Permission.objects.all().order_by("id")
    serializer_class = PermissionSerializer
    pagination_class = MyPagination

    @action(methods=["get"], detail=False)
    def content_types(self, request):
        contents_model = ContentType.objects.all()
        serializer = ContentTypeSerializer(instance=contents_model, many=True)
        return Response(serializer.data)




